package com.baidu.cmsCommes.pojo;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Author: BSS
 * @create: 2020/6/23/16:29
 */
public class MyTypeHandle implements TypeHandler<ChannelType> {

    public void setParameter(PreparedStatement preparedStatement, int i, ChannelType channelType, JdbcType jdbcType) throws SQLException {
        preparedStatement.setString(i, channelType.getCode().toString());
    }

    public ChannelType getResult(ResultSet rs, String columnName) throws SQLException {
        //从数据库中得到的值
        int code = rs.getInt(columnName);
        //从数据库中得到的枚举状态码返回枚举对象
        return ChannelType.valueOfClass(code);
    }

    public ChannelType getResult(ResultSet rs, int columnIndex) throws SQLException {
        //从数据库中得到的值
        int code = rs.getInt(columnIndex);
        //从数据库中得到的枚举状态码返回枚举对象
        return ChannelType.valueOfClass(code);
    }

    public ChannelType getResult(CallableStatement cs, int columnIndex) throws SQLException {
        //从数据库中得到的值
        int code = cs.getInt(columnIndex);
        //从数据库中得到的枚举状态码返回枚举对象
        return ChannelType.valueOfClass(code);
    }

}
